package com.example.smartcity_poverty.ui.PersonalCenter.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.MenuItem
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.example.smartcity_poverty.R
import com.example.smartcity_poverty.ui.AllService.SmartBus.fragment.BusFragment1
import com.example.smartcity_poverty.ui.AllService.SmartBus.fragment.BusFragment1.Companion.personId
import com.google.android.material.tabs.TabLayoutMediator
import kotlinx.android.synthetic.main.activity_list.*

/**
 * 智慧巴士订单列表
 */
class ListActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        supportActionBar?.setDisplayHomeAsUpEnabled(true)
        setContentView(R.layout.activity_list)
        title = "订单列表"

        val tab = personTabLayout
        val vp = personViewPager2

        val strTitle = listOf<String>("待支付", "已支付订单")

        vp.adapter = object : FragmentStateAdapter(this){
            override fun getItemCount(): Int = 2

            override fun createFragment(position: Int): Fragment = when(position){
                0 -> BusFragment1()
                else -> BusFragment1()
            }

            override fun getItemId(position: Int): Long {
                personId = when(position){
                    0 -> 0
                    else -> 1
                }
                return super.getItemId(position)
            }

        }

        TabLayoutMediator(tab, vp){ tab1, position ->
            when(position){
                0 -> tab1.text = strTitle[0]
                else -> tab1.text = strTitle[1]
            }
        }.attach()
    }

    fun setFinish(){
        finish()
    }

    override fun onOptionsItemSelected(item: MenuItem): Boolean {
        finish()
        return super.onOptionsItemSelected(item)
    }
}